package com.spring.controller;

import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.atomic.AtomicLong;


public class CounterInterceptor implements HandlerInterceptor {

    private AtomicLong atomicLong=new AtomicLong(1);
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("==CounterInterceptor.preHandler==");
        Long count=atomicLong.getAndIncrement();
        if(count==5)
            throw new RuntimeException("您的访问次数太多了，被限制了");
        return true;
    }
}

